//
//  NetWorkHandler.h
//  NetWorkMgr
//
//  Created by cst_han on 12-8-8.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "GamePID.pb.h"
#import "CallbackDelegate.h"
#define WRITE_DATA      3333
#define READ_HEADER     1111
#define READ_BODY       2222
#define HEADER_SIZE     7
@class GCDAsyncSocket;

@interface NetWorkHandler : NSObject
{
    
    //connect-using variable
    GCDAsyncSocket *asyncSocket_;
    
    NSString *connSrvAddr_;
    
    uint16_t connSrvPort_;

    //check if socket is connecting to server
    BOOL isInConnecting_;
    
    
    //Handle_transData-using variable
    @public
    //counting recv bytes
        int shouldRcvBytes_,recvBytes_,continueRcvBytes_;
    
    @public 
    //recving PID type
        PID recvPID_;
    @public
        id <CallbackDelegate> callbackDelegate;
   

}
@property (retain,nonatomic)NSMutableData *sendBuf_;
@property (retain,nonatomic)NSMutableData *recvBuf_;
@property (retain,nonatomic)NSUserDefaults *userDefaults_;
-(BOOL)initConn;


-(void)initSocket;

-(BOOL)connectToSrv;
-(BOOL)disConnect;
-(BOOL)sendData:(NSData *)arg_sendData Pid:(PID )arg_pid;
-(BOOL)isSocketConnected;

-(BOOL)readWithSpecificSize:(int)arg_size tag:(long)arg_tag;

-(BOOL)parseHeader:(NSData *)arg_data;
-(BOOL)parseContentByPID:(NSData *)arg_data;

-(void)resetInvali;

-(BOOL)handle_read:(NSData *)arg_data tag:(long)arg_tag;

-(GCDAsyncSocket *)getSocket;


-(void)setIsInConnecting:(BOOL)arg_switch;

-(BOOL)getIsInConnecting;
@end
